package sy.controller;

import java.util.List;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import sy.jackson.SysOwnerRenterMappingMixin;
import sy.jackson.SysUnitMixin;
import sy.jackson.SysUserMixin;
import sy.model.SysAccount;
import sy.model.SysBuilding;
import sy.model.SysOwnerRenterMapping;
import sy.model.SysProject;
import sy.model.SysUnit;
import sy.model.SysUser;
import sy.model.SysVisitor;
import sy.service.SysAccountServiceI;
import sy.service.SysOwnerRenterMappingServiceI;
import sy.service.SysProjectServiceI;
import sy.service.SysUnitServiceI;
import sy.service.SysUserServiceI;
import sy.service.SysVisitorServiceI;
import sy.util.MessageObject;

@Controller
@RequestMapping("ownerRenterController")
@SessionAttributes("currAccount")
public class OwnerRenterController {
	
	@Autowired
	private SysOwnerRenterMappingServiceI sysOwnerRenterMappingService;
	private static final ObjectMapper objectMapper = new ObjectMapper();

	/************************** view controller ***************************/

	/**
	 * 
		 * @Title      : objectView
		 * @Description: 首页试图
		 * @param      : model
		 * @return     : String
		 * @author     : jiayiwu
		 * @time       : 2017年8月29日 下午2:24:38
		 * @throws
	 */
	@RequestMapping(value="/view")
	public String objectView(Model model){
		List<SysOwnerRenterMapping> ownerRenterList = sysOwnerRenterMappingService.list();
		
		model.addAttribute("ownerRenterList",ownerRenterList);
		return "userInfo/ownerRenter/ownerRenter";
	}
		
	/************************** data controller ***************************/
	
	/**
	 * @Description: 返回全部json数据
	 * @param 
	 * @author     :wjy
	 * Create Date : 2017年7月26日 
	 */
	@ResponseBody
	@RequestMapping(value = "/getAllData", method = RequestMethod.POST,produces={"text/html;charset=UTF-8"})
	private String getAllData(HttpServletResponse response) {
		objectMapper.addMixInAnnotations(SysOwnerRenterMapping.class, SysOwnerRenterMappingMixin.BasicInfo.class);
		List<SysOwnerRenterMapping> ownerRenterList = sysOwnerRenterMappingService.list();
		try {
			return objectMapper.writeValueAsString(ownerRenterList);
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "";
	}
	
}
